import requests
import json

# 从配置文件加载配置
with open('config.json', 'r', encoding='utf-8') as config_file:
    config = json.load(config_file)

api_key = config['api_key']
url = config['url']
model = config['model']

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {api_key}'
}

data = {
    'model': model,
    'messages': [{'role': 'user', "content": [
                {
                    "type": "text",
                    "text": "这张图片中有什么动物？用中文回答"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://p8.itc.cn/images01/20230325/2d84325fd8cc4f78ad169434c0e288aa.png"
                    }
                }
            ]}],
}

try:
    response = requests.post(url, headers=headers, json=data)
    response.raise_for_status()  # Raises an exception for HTTP errors
    print(response.json())  # Print the JSON response
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")
